/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using System.Collections.Generic;
using NetProtocol.POD;
using NetProtocol.Enum;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay;
using IQIGame.Onigao.Framework;
using Cysharp.Threading.Tasks;
using System;
using static IQIGame.Onigao.Game.MessageWrapper;

namespace NetProtocol.Client {
	/// <summary>
	/// 大厅房间匹配模块
	/// module : room
	/// </summary>
	public interface CNetRoom : INetClientModule {
		
		public ISession GetSession();
	
		Dictionary<int, INetClientModule.Package2MessageWrapper> INetClientModule.GetModuleFunction()
        {
            MessageFunction notifyRoomInfo_Delegate = (session, wrapper) =>
            {
            var _wrapper = (MessageWrapper<NotifyRoomInfoData>)wrapper; 
#if ENABLE_NET_LOG || UNITY_EDITOR
            NetProtocolHelper.ClientLog(NetMessageId.room_notifyRoomInfo, "Recv->" + _wrapper.message.ToString());
#endif
                SC_notifyRoomInfo(session, _wrapper.message.roomPod, _wrapper.message.reason);
                MessageWrapperPool<NotifyRoomInfoData>.Put(_wrapper);
            };
            MessageFunction notifyRoomSimpleInfo_Delegate = (session, wrapper) =>
            {
            var _wrapper = (MessageWrapper<NotifyRoomSimpleInfoData>)wrapper; 
#if ENABLE_NET_LOG || UNITY_EDITOR
            NetProtocolHelper.ClientLog(NetMessageId.room_notifyRoomSimpleInfo, "Recv->" + _wrapper.message.ToString());
#endif
                SC_notifyRoomSimpleInfo(session, _wrapper.message.roomPod, _wrapper.message.reason);
                MessageWrapperPool<NotifyRoomSimpleInfoData>.Put(_wrapper);
            };
            MessageFunction notifyMatchState_Delegate = (session, wrapper) =>
            {
            var _wrapper = (MessageWrapper<NotifyMatchStateData>)wrapper; 
#if ENABLE_NET_LOG || UNITY_EDITOR
            NetProtocolHelper.ClientLog(NetMessageId.room_notifyMatchState, "Recv->" + _wrapper.message.ToString());
#endif
                SC_notifyMatchState(session, _wrapper.message.matchStatePOD, _wrapper.message.reason);
                MessageWrapperPool<NotifyMatchStateData>.Put(_wrapper);
            };
            MessageFunction createRoomResult_Delegate = (session, wrapper) =>
            {
            	var _wrapper = (MessageWrapper<CreateRoomResultData>)wrapper;
                SC_createRoomResult(session, ref _wrapper.message);
                MessageWrapperPool<CreateRoomResultData>.Put(_wrapper);
            };
            MessageFunction leaveRoomResult_Delegate = (session, wrapper) =>
            {
            	var _wrapper = (MessageWrapper<LeaveRoomResultData>)wrapper;
                SC_leaveRoomResult(session, ref _wrapper.message);
                MessageWrapperPool<LeaveRoomResultData>.Put(_wrapper);
            };
            MessageFunction joinRoomResult_Delegate = (session, wrapper) =>
            {
            	var _wrapper = (MessageWrapper<JoinRoomResultData>)wrapper;
                SC_joinRoomResult(session, ref _wrapper.message);
                MessageWrapperPool<JoinRoomResultData>.Put(_wrapper);
            };
            MessageFunction requestMatchResult_Delegate = (session, wrapper) =>
            {
            	var _wrapper = (MessageWrapper<RequestMatchResultData>)wrapper;
                SC_requestMatchResult(session, ref _wrapper.message);
                MessageWrapperPool<RequestMatchResultData>.Put(_wrapper);
            };
            MessageFunction cancelMatchResult_Delegate = (session, wrapper) =>
            {
            	var _wrapper = (MessageWrapper<CancelMatchResultData>)wrapper;
                SC_cancelMatchResult(session, ref _wrapper.message);
                MessageWrapperPool<CancelMatchResultData>.Put(_wrapper);
            };
        
            Dictionary<int, INetClientModule.Package2MessageWrapper> retDic = new()
            {
                {NetMessageId.room_notifyRoomInfo, (session, package) => {
                	var result = MessageWrapperPool<NotifyRoomInfoData>.Get();
                	result.Init(session, notifyRoomInfo_Delegate);
                	result.FromPackage(package);
                	return result;
                }},
                {NetMessageId.room_notifyRoomSimpleInfo, (session, package) => {
                	var result = MessageWrapperPool<NotifyRoomSimpleInfoData>.Get();
                	result.Init(session, notifyRoomSimpleInfo_Delegate);
                	result.FromPackage(package);
                	return result;
                }},
                {NetMessageId.room_notifyMatchState, (session, package) => {
                	var result = MessageWrapperPool<NotifyMatchStateData>.Get();
                	result.Init(session, notifyMatchState_Delegate);
                	result.FromPackage(package);
                	return result;
                }},
                {NetMessageId.room_createRoomResult, (session, package) => {
                	var result = MessageWrapperPool<CreateRoomResultData>.Get();
                	result.Init(session, createRoomResult_Delegate);
                	result.FromPackage(package);
                	return result;
                }},
                {NetMessageId.room_leaveRoomResult, (session, package) => {
                	var result = MessageWrapperPool<LeaveRoomResultData>.Get();
                	result.Init(session, leaveRoomResult_Delegate);
                	result.FromPackage(package);
                	return result;
                }},
                {NetMessageId.room_joinRoomResult, (session, package) => {
                	var result = MessageWrapperPool<JoinRoomResultData>.Get();
                	result.Init(session, joinRoomResult_Delegate);
                	result.FromPackage(package);
                	return result;
                }},
                {NetMessageId.room_requestMatchResult, (session, package) => {
                	var result = MessageWrapperPool<RequestMatchResultData>.Get();
                	result.Init(session, requestMatchResult_Delegate);
                	result.FromPackage(package);
                	return result;
                }},
                {NetMessageId.room_cancelMatchResult, (session, package) => {
                	var result = MessageWrapperPool<CancelMatchResultData>.Get();
                	result.Init(session, cancelMatchResult_Delegate);
                	result.FromPackage(package);
                	return result;
                }},
            };
            return retDic;
        }
#region Client-side Interface
		/// <summary>
        /// 
        /// </summary>
		protected void SC_notifyRoomInfo(ISession session, RoomPOD roomPod, RoomActionReason reason);
		/// <summary>
        /// 
        /// </summary>
		protected void SC_notifyRoomSimpleInfo(ISession session, RoomPOD roomPod, RoomActionReason reason);
		/// <summary>
        /// 
        /// </summary>
		protected void SC_notifyMatchState(ISession session, MatchStatePOD matchStatePOD, RoomMatchReason reason);
		/// <summary>
        ///  该协议仅用于提示；roomId用于校验	
        /// </summary>
		public void SC_createRoomResult(ISession session, ref CreateRoomResultData message) 
		{
            _SC_createRoomResult(session, ref message);
		}
		
		public void _SC_createRoomResult(ISession session, ref CreateRoomResultData message)
		{
#if ENABLE_NET_LOG || UNITY_EDITOR
            NetProtocolHelper.ClientLog(NetMessageId.room_createRoomResult, "Recv->" + message.ToString());
#endif
			NetProtocolHelper.endCallRequest?.Invoke(NetMessageId.room_createRoomResult, message.code);
			MsgAsyncAwaiter<CreateRoomResultData>.Instance.CompleteMsgAwait(ref message);
		}
		
		/// <summary>
        ///  该协议仅用于提示
        /// </summary>
		public void SC_leaveRoomResult(ISession session, ref LeaveRoomResultData message) 
		{
            _SC_leaveRoomResult(session, ref message);
		}
		
		public void _SC_leaveRoomResult(ISession session, ref LeaveRoomResultData message)
		{
#if ENABLE_NET_LOG || UNITY_EDITOR
            NetProtocolHelper.ClientLog(NetMessageId.room_leaveRoomResult, "Recv->" + message.ToString());
#endif
			NetProtocolHelper.endCallRequest?.Invoke(NetMessageId.room_leaveRoomResult, message.code);
			MsgAsyncAwaiter<LeaveRoomResultData>.Instance.CompleteMsgAwait(ref message);
		}
		
		/// <summary>
        ///  该协议仅用于提示
        /// </summary>
		public void SC_joinRoomResult(ISession session, ref JoinRoomResultData message) 
		{
            _SC_joinRoomResult(session, ref message);
		}
		
		public void _SC_joinRoomResult(ISession session, ref JoinRoomResultData message)
		{
#if ENABLE_NET_LOG || UNITY_EDITOR
            NetProtocolHelper.ClientLog(NetMessageId.room_joinRoomResult, "Recv->" + message.ToString());
#endif
			NetProtocolHelper.endCallRequest?.Invoke(NetMessageId.room_joinRoomResult, message.code);
			MsgAsyncAwaiter<JoinRoomResultData>.Instance.CompleteMsgAwait(ref message);
		}
		
		/// <summary>
        ///  该协议仅用于提示
        /// </summary>
		public void SC_requestMatchResult(ISession session, ref RequestMatchResultData message) 
		{
            _SC_requestMatchResult(session, ref message);
		}
		
		public void _SC_requestMatchResult(ISession session, ref RequestMatchResultData message)
		{
#if ENABLE_NET_LOG || UNITY_EDITOR
            NetProtocolHelper.ClientLog(NetMessageId.room_requestMatchResult, "Recv->" + message.ToString());
#endif
			NetProtocolHelper.endCallRequest?.Invoke(NetMessageId.room_requestMatchResult, message.code);
			MsgAsyncAwaiter<RequestMatchResultData>.Instance.CompleteMsgAwait(ref message);
		}
		
		/// <summary>
        ///  该协议仅用于提示
        /// </summary>
		public void SC_cancelMatchResult(ISession session, ref CancelMatchResultData message) 
		{
            _SC_cancelMatchResult(session, ref message);
		}
		
		public void _SC_cancelMatchResult(ISession session, ref CancelMatchResultData message)
		{
#if ENABLE_NET_LOG || UNITY_EDITOR
            NetProtocolHelper.ClientLog(NetMessageId.room_cancelMatchResult, "Recv->" + message.ToString());
#endif
			NetProtocolHelper.endCallRequest?.Invoke(NetMessageId.room_cancelMatchResult, message.code);
			MsgAsyncAwaiter<CancelMatchResultData>.Instance.CompleteMsgAwait(ref message);
		}
		
#endregion
#region Server-side Interface
		/// <summary>
        ///  创建房间
        /// </summary>
    	public UniTask<CreateRoomResultData> CS_createRoom()
        {
            return _CS_createRoom();
        }
        
        public UniTask<CreateRoomResultData> _CS_createRoom()
        {
        	ISession session = GetSession();
        	if(session == null) return UniTask.FromResult(default(CreateRoomResultData));
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_createRoom, "Send->"+"Room.CS_createRoom { "
				+" }");
#endif
        	UniTask<CreateRoomResultData> task = MsgAsyncAwaiter<CreateRoomResultData>.Instance.AddMsgAwait();
        	session.SendPack(Pack_for_createRoom());
        	NetProtocolHelper.beginCallRequest?.Invoke(NetMessageId.room_createRoomResult);
			return task;
        }
		
		public static SendPackage Pack_for_createRoom() 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_createRoom;
			si_p.StartWrite();
			return si_p;
		}
		/// <summary>
        ///  离开房间，roomId用于校验
        /// </summary>
    	public UniTask<LeaveRoomResultData> CS_leaveRoom(long roomId)
        {
            return _CS_leaveRoom(roomId);
        }
        
        public UniTask<LeaveRoomResultData> _CS_leaveRoom(long roomId)
        {
        	ISession session = GetSession();
        	if(session == null) return UniTask.FromResult(default(LeaveRoomResultData));
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_leaveRoom, "Send->"+"Room.CS_leaveRoom { "
				+ "roomId="
				+ roomId
				+" }");
#endif
        	UniTask<LeaveRoomResultData> task = MsgAsyncAwaiter<LeaveRoomResultData>.Instance.AddMsgAwait();
        	session.SendPack(Pack_for_leaveRoom(roomId));
        	NetProtocolHelper.beginCallRequest?.Invoke(NetMessageId.room_leaveRoomResult);
			return task;
        }
		
		public static SendPackage Pack_for_leaveRoom(long roomId) 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_leaveRoom;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_long(roomId);
			return si_p;
		}
		/// <summary>
        ///  请求加入房间
        /// </summary>
    	public UniTask<JoinRoomResultData> CS_joinRoom(long roomId)
        {
            return _CS_joinRoom(roomId);
        }
        
        public UniTask<JoinRoomResultData> _CS_joinRoom(long roomId)
        {
        	ISession session = GetSession();
        	if(session == null) return UniTask.FromResult(default(JoinRoomResultData));
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_joinRoom, "Send->"+"Room.CS_joinRoom { "
				+ "roomId="
				+ roomId
				+" }");
#endif
        	UniTask<JoinRoomResultData> task = MsgAsyncAwaiter<JoinRoomResultData>.Instance.AddMsgAwait();
        	session.SendPack(Pack_for_joinRoom(roomId));
        	NetProtocolHelper.beginCallRequest?.Invoke(NetMessageId.room_joinRoomResult);
			return task;
        }
		
		public static SendPackage Pack_for_joinRoom(long roomId) 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_joinRoom;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_long(roomId);
			return si_p;
		}
		/// <summary>
        ///  匹配可能有筛选参数
        /// </summary>
    	public UniTask<RequestMatchResultData> CS_requestMatch(MatchRequestPOD requestPod)
        {
            return _CS_requestMatch(requestPod);
        }
        
        public UniTask<RequestMatchResultData> _CS_requestMatch(MatchRequestPOD requestPod)
        {
        	ISession session = GetSession();
        	if(session == null) return UniTask.FromResult(default(RequestMatchResultData));
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_requestMatch, "Send->"+"Room.CS_requestMatch { "
				+ "requestPod="
				+ requestPod
				+" }");
#endif
        	UniTask<RequestMatchResultData> task = MsgAsyncAwaiter<RequestMatchResultData>.Instance.AddMsgAwait();
        	session.SendPack(Pack_for_requestMatch(requestPod));
        	NetProtocolHelper.beginCallRequest?.Invoke(NetMessageId.room_requestMatchResult);
			return task;
        }
		
		public static SendPackage Pack_for_requestMatch(MatchRequestPOD requestPod) 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_requestMatch;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_pod(requestPod);
			return si_p;
		}
		/// <summary>
        /// 
        /// </summary>
    	public UniTask<CancelMatchResultData> CS_cancelMatch()
        {
            return _CS_cancelMatch();
        }
        
        public UniTask<CancelMatchResultData> _CS_cancelMatch()
        {
        	ISession session = GetSession();
        	if(session == null) return UniTask.FromResult(default(CancelMatchResultData));
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_cancelMatch, "Send->"+"Room.CS_cancelMatch { "
				+" }");
#endif
        	UniTask<CancelMatchResultData> task = MsgAsyncAwaiter<CancelMatchResultData>.Instance.AddMsgAwait();
        	session.SendPack(Pack_for_cancelMatch());
        	NetProtocolHelper.beginCallRequest?.Invoke(NetMessageId.room_cancelMatchResult);
			return task;
        }
		
		public static SendPackage Pack_for_cancelMatch() 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_cancelMatch;
			si_p.StartWrite();
			return si_p;
		}
		/// <summary>
        ///  变更房间关卡，0表示取消指定
        /// </summary>
    	public bool CS_changeLevel(int levelCid) 
    	{
    		return _CS_changeLevel(levelCid);
    	}
    	public bool _CS_changeLevel(int levelCid)
        {
        	ISession session = GetSession();
        	if(session == null) return false;
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_changeLevel, "Send->"+"Room.CS_changeLevel { "
				+ "levelCid="
				+ levelCid
				+" }");
#endif
        	return session.SendPack(Pack_for_changeLevel(levelCid));
        }
		
		public static SendPackage Pack_for_changeLevel(int levelCid) 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_changeLevel;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(levelCid);
			return si_p;
		}
		/// <summary>
        ///  请求进入关卡，可能进入非当前关卡 -- 暂不制作进入确认
        /// </summary>
    	public bool CS_requestEnter(int levelCid) 
    	{
    		return _CS_requestEnter(levelCid);
    	}
    	public bool _CS_requestEnter(int levelCid)
        {
        	ISession session = GetSession();
        	if(session == null) return false;
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_requestEnter, "Send->"+"Room.CS_requestEnter { "
				+ "levelCid="
				+ levelCid
				+" }");
#endif
        	return session.SendPack(Pack_for_requestEnter(levelCid));
        }
		
		public static SendPackage Pack_for_requestEnter(int levelCid) 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_requestEnter;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(levelCid);
			return si_p;
		}
		/// <summary>
        ///  踢出指定玩家，房主可操作 -- 以下协议暂不制作
        /// </summary>
    	public bool CS_kickoutPlayer(long targetPid) 
    	{
    		return _CS_kickoutPlayer(targetPid);
    	}
    	public bool _CS_kickoutPlayer(long targetPid)
        {
        	ISession session = GetSession();
        	if(session == null) return false;
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_kickoutPlayer, "Send->"+"Room.CS_kickoutPlayer { "
				+ "targetPid="
				+ targetPid
				+" }");
#endif
        	return session.SendPack(Pack_for_kickoutPlayer(targetPid));
        }
		
		public static SendPackage Pack_for_kickoutPlayer(long targetPid) 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_kickoutPlayer;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_long(targetPid);
			return si_p;
		}
		/// <summary>
        ///  关闭座位	
        /// </summary>
    	public bool CS_closeSeat(int seatNum) 
    	{
    		return _CS_closeSeat(seatNum);
    	}
    	public bool _CS_closeSeat(int seatNum)
        {
        	ISession session = GetSession();
        	if(session == null) return false;
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_closeSeat, "Send->"+"Room.CS_closeSeat { "
				+ "seatNum="
				+ seatNum
				+" }");
#endif
        	return session.SendPack(Pack_for_closeSeat(seatNum));
        }
		
		public static SendPackage Pack_for_closeSeat(int seatNum) 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_closeSeat;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(seatNum);
			return si_p;
		}
		/// <summary>
        ///  开启座位
        /// </summary>
    	public bool CS_openSeat(int seatNum) 
    	{
    		return _CS_openSeat(seatNum);
    	}
    	public bool _CS_openSeat(int seatNum)
        {
        	ISession session = GetSession();
        	if(session == null) return false;
#if ENABLE_NET_LOG || UNITY_EDITOR
			NetProtocolHelper.ClientLog(NetMessageId.room_openSeat, "Send->"+"Room.CS_openSeat { "
				+ "seatNum="
				+ seatNum
				+" }");
#endif
        	return session.SendPack(Pack_for_openSeat(seatNum));
        }
		
		public static SendPackage Pack_for_openSeat(int seatNum) 
		{
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.room_openSeat;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(seatNum);
			return si_p;
		}
#endregion
#region Messages
        public struct NotifyRoomInfoData : IReceiveMessage {
	        public RoomPOD roomPod;
	        public RoomActionReason reason;
            public void FromPackage(ReceivePackage _package)
            {
                SInputStream _in = _package.InputStream;
                roomPod = _in.HasRemaining() ? _in.Read_pod<RoomPOD>(RoomPOD.DynamicFactory) : default;
                reason = _in.HasRemaining() ? (RoomActionReason)_in.Read_byte() : default;
            }
            
            public int GetMessageId() {return NetMessageId.room_notifyRoomInfo;}
            
            public override string ToString()
            {
                return "Room.notifyRoomInfo"+ ", roomPod="+ roomPod+ ", reason="+ reason;
            }
        }
        public struct NotifyRoomSimpleInfoData : IReceiveMessage {
	        public RoomPOD roomPod;
	        public RoomActionReason reason;
            public void FromPackage(ReceivePackage _package)
            {
                SInputStream _in = _package.InputStream;
                roomPod = _in.HasRemaining() ? _in.Read_pod<RoomPOD>(RoomPOD.DynamicFactory) : default;
                reason = _in.HasRemaining() ? (RoomActionReason)_in.Read_byte() : default;
            }
            
            public int GetMessageId() {return NetMessageId.room_notifyRoomSimpleInfo;}
            
            public override string ToString()
            {
                return "Room.notifyRoomSimpleInfo"+ ", roomPod="+ roomPod+ ", reason="+ reason;
            }
        }
        public struct NotifyMatchStateData : IReceiveMessage {
	        public MatchStatePOD matchStatePOD;
	        public RoomMatchReason reason;
            public void FromPackage(ReceivePackage _package)
            {
                SInputStream _in = _package.InputStream;
                matchStatePOD = _in.HasRemaining() ? _in.Read_pod<MatchStatePOD>(MatchStatePOD.DynamicFactory) : default;
                reason = _in.HasRemaining() ? (RoomMatchReason)_in.Read_byte() : default;
            }
            
            public int GetMessageId() {return NetMessageId.room_notifyMatchState;}
            
            public override string ToString()
            {
                return "Room.notifyMatchState"+ ", matchStatePOD="+ matchStatePOD+ ", reason="+ reason;
            }
        }
        public struct CreateRoomResultData : IReceiveMessage {
        	private int? _code;
        	public int code {get{return _code == null ? -1 : (int)_code;}private set{_code = value;}}
	        public long roomId;
            public bool IsFail => _code != null && _code != 0;
            public bool IsSuccess =>_code != null && _code == 0;
            public bool IsCanceled => _code == null;
            public void FromPackage(ReceivePackage _package)
            {
                SInputStream _in = _package.InputStream;
                code = _in.HasRemaining() ? _in.Read_int() : default;
                roomId = _in.HasRemaining() ? _in.Read_long() : default;
            }
            
            public int GetMessageId() {return NetMessageId.room_createRoomResult;}
            
            public override string ToString()
            {
                return "Room.createRoomResult"+ ", code="+ code+ ", roomId="+ roomId;
            }
        }
        public struct LeaveRoomResultData : IReceiveMessage {
        	private int? _code;
        	public int code {get{return _code == null ? -1 : (int)_code;}private set{_code = value;}}
            public bool IsFail => _code != null && _code != 0;
            public bool IsSuccess =>_code != null && _code == 0;
            public bool IsCanceled => _code == null;
            public void FromPackage(ReceivePackage _package)
            {
                SInputStream _in = _package.InputStream;
                code = _in.HasRemaining() ? _in.Read_int() : default;
            }
            
            public int GetMessageId() {return NetMessageId.room_leaveRoomResult;}
            
            public override string ToString()
            {
                return "Room.leaveRoomResult"+ ", code="+ code;
            }
        }
        public struct JoinRoomResultData : IReceiveMessage {
        	private int? _code;
        	public int code {get{return _code == null ? -1 : (int)_code;}private set{_code = value;}}
            public bool IsFail => _code != null && _code != 0;
            public bool IsSuccess =>_code != null && _code == 0;
            public bool IsCanceled => _code == null;
            public void FromPackage(ReceivePackage _package)
            {
                SInputStream _in = _package.InputStream;
                code = _in.HasRemaining() ? _in.Read_int() : default;
            }
            
            public int GetMessageId() {return NetMessageId.room_joinRoomResult;}
            
            public override string ToString()
            {
                return "Room.joinRoomResult"+ ", code="+ code;
            }
        }
        public struct RequestMatchResultData : IReceiveMessage {
        	private int? _code;
        	public int code {get{return _code == null ? -1 : (int)_code;}private set{_code = value;}}
            public bool IsFail => _code != null && _code != 0;
            public bool IsSuccess =>_code != null && _code == 0;
            public bool IsCanceled => _code == null;
            public void FromPackage(ReceivePackage _package)
            {
                SInputStream _in = _package.InputStream;
                code = _in.HasRemaining() ? _in.Read_int() : default;
            }
            
            public int GetMessageId() {return NetMessageId.room_requestMatchResult;}
            
            public override string ToString()
            {
                return "Room.requestMatchResult"+ ", code="+ code;
            }
        }
        public struct CancelMatchResultData : IReceiveMessage {
        	private int? _code;
        	public int code {get{return _code == null ? -1 : (int)_code;}private set{_code = value;}}
            public bool IsFail => _code != null && _code != 0;
            public bool IsSuccess =>_code != null && _code == 0;
            public bool IsCanceled => _code == null;
            public void FromPackage(ReceivePackage _package)
            {
                SInputStream _in = _package.InputStream;
                code = _in.HasRemaining() ? _in.Read_int() : default;
            }
            
            public int GetMessageId() {return NetMessageId.room_cancelMatchResult;}
            
            public override string ToString()
            {
                return "Room.cancelMatchResult"+ ", code="+ code;
            }
        }
    }
#endregion
}